# Docker Build Stage
#FROM maven:3-jdk-8-alpine AS build
# 使用 Java 11 的 Maven 镜像
FROM maven:3.8.6-jdk-11 AS build


RUN cat /usr/share/maven/conf/settings.xml

#RUN sed -i 's#https://repo.maven.apache.org/maven2#https://maven.aliyun.com/repository/public#g' /usr/share/maven/conf/settings.xml
RUN sed -i \
    -e 's#<mirrors>#<mirrors><mirror><id>aliyun</id><name>Aliyun Maven Mirror</name><url>https://maven.aliyun.com/repository/public</url><mirrorOf>central</mirrorOf></mirror>#' \
    -e 's#https://repo.maven.apache.org/maven2#https://maven.aliyun.com/repository/public#g' \
    /usr/share/maven/conf/settings.xml

RUN cat /usr/share/maven/conf/settings.xml

# Build Stage
WORKDIR /opt/app

COPY ./ /opt/app
RUN mvn clean install -DskipTests


# Docker Build Stage
#FROM openjdk:8-jdk-alpine
# 使用 Java 11 的运行时镜像
FROM openjdk:11-jre-slim

COPY --from=build /opt/app/target/*.jar app.jar

ENV PORT 8081
EXPOSE $PORT

ENTRYPOINT ["java","-jar","-Xmx1024M","-Dserver.port=${PORT}","app.jar"]

